home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 141_01.zip / SPIRAL.C < prev    next >
Text File  |  1993-06-01  |  2KB  |  80 lines

  1. /* spiral.c -- drawing */
  2. /* 1984 apr 29 pmkrasno */
  3. #include "bdscio.h"
  4. #include "float.h"
  5. #define SCALE "90.0" /* screen points, near full scale */
  6. #define TURNS 19
  7. #define WH 1    /* colors */
  8. #define BL 15
  9. #define NPTS 180
  10. #define wait pause () ; getchar () 
  11.  
  12. float turns[1], r[1] ;    /* extern */
  13.  
  14. main ()    {    /* calc x, y & plot */
  15.     float theta[2+NPTS], y[4+2*NPTS], delta, del ;
  16.     float *xcoord(), *ycoord(), scale ;
  17.     unsigned n, nfcns, npts, secs1, secs2 ;
  18.     int nt ;
  19.     byte time1[13], time2[13], time3[13] ;
  20.     byte dif12[13+5], dif23[13+5] ;
  21.  
  22.     nfcns = 2 ; /* # functions (x, y) */
  23.     fpdiv (del, TWOPI, itof (del, NPTS) ) ;
  24.     mode2 () ; cls (BL, WH) ;     npts = NPTS + 2 ;
  25.  
  26.     while (TRUE) {
  27.         do {    printf ("Turns (1-%d) ? ", TURNS) ;
  28.             scanf ("%d", &nt) ;
  29.             } while ( (nt < 1) 
  30.                 || (TURNS < nt) ) ;
  31.         fpmult (delta, del, itof (turns, nt) ) ;
  32.         syst_d (time1) ; 
  33.         printf ("Evaluate %3d points: %s\N", 
  34.             npts, time1) ;
  35.         comp_pts(npts, nfcns, theta, y, ZERO, 
  36.             delta, xcoord, ycoord) ;
  37.  
  38.         syst_d (time2) ;
  39.         fpdiv (scale, atof (scale, SCALE), r) ;
  40.         printf ("Plot %3d points:     %s\N", 
  41.             npts, time2) ;
  42.         cls (WH, BL) ;
  43.         plot_lins (npts, nfcns-1, y, y+npts, 
  44.             scale, scale) ;
  45.  
  46.         syst_d (time3) ;
  47.         printf ("Done :               %s\N", time3) ;
  48.         secs1 = tim_dif (dif12, time2, time1) ;
  49.         secs2 = tim_dif (dif23, time2, time3) ;
  50.         /* convert differences to seconds */
  51.         printf ("Evaluate: %d secs; Plot: %d secs\N", 
  52.             secs1, secs2) ;
  53.     } /* forever */
  54. } /* main */
  55.  
  56. float *log (res, xin) float *res, *xin ;    {
  57.     int sign ;    float *log10 () ;
  58.     log10 (res, &sign, xin) ;
  59.     if ( sign < 0 ) fpchs (res, res) ;
  60.     return (res) ;
  61. } /* log */
  62.  
  63. float *xcoord (x, theta) float *x, *theta ;    {
  64.     float *sine(), *cosine(), t ; /* save r for y */
  65.     /* r = theta / turns ;    */
  66.     /* x = r * sin (theta) ;    */
  67.     fpdiv (r, theta, turns) ;
  68.     fpmult (x, sine (t, theta), r) ;
  69.     return fpchs (x, x) ;
  70. } /* xcoord */
  71.  
  72. float *ycoord (y, theta) float *y, *theta ;    {
  73.     float *sine(), *cosine(), t ; /* r saved by x */
  74.     /* y = r * cos (theta) ;    */
  75.     fpmult (y, cosine (t, theta), r) ;
  76.     return fpchs (y, y) ;
  77. } /* ycoord */
  78.  
  79. ;
  80.         cls